//
//  DSNavBaseViewController.m
//  广四生活圈-demo
//
//  Created by Mac on 15/8/10.
//  Copyright (c) 2015年 Itcast. All rights reserved.
//

#import "DSNavBaseViewController.h"

@interface DSNavBaseViewController ()

@end


#define kNavStatusHeight 20
#define kNavButtonWidth 44
#define kNavButtonHeight 44

@implementation DSNavBaseViewController
//kUIScreenWidth

//创建自定义导航 navView
//frame
-(void)viewDidLoad{
    _navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUINavHeight)];
    
    _navView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:_navView];
    
    
    _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    _leftButton.frame = CGRectMake(0, kNavStatusHeight, kNavButtonWidth,kNavButtonHeight);
    
    [_leftButton setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    
    
    [_leftButton addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    
    [_navView addSubview:_leftButton];
    
    _titleLabel =[[UILabel alloc]initWithFrame:CGRectZero];
    _titleLabel.textColor =[UIColor whiteColor];
    _titleLabel.font =[UIFont systemFontOfSize:18];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.text =@"电商";
    [_navView addSubview:_titleLabel];
    
    
    _rightButton =[UIButton buttonWithType:UIButtonTypeCustom];
//    _rightButton.frame =CGRectMake(kUIScreenWidth -kn, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
    
    [_rightButton addTarget:self action:@selector(loginMethod) forControlEvents:UIControlEventTouchUpInside];
    
    [_navView addSubview:_rightButton];

    
}

-(void)backMethod{


}

-(void)loginMethod{

}
//创建leftButton  rightButton  titleLabel


//界面载入前调用方法
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
//    第一个参数 给计算的一个参考宽高
//    第二个参数
//    第三个参数 设置一些属性

    CGRect rect =[_titleLabel.text boundingRectWithSize:CGSizeZero options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} context:nil];
    
     /*
      我写的frame 错误了
      _titleLabel.frame =CGRectMake((kUIScreenWidth-rect.size.width)/2, (44- rect.size.height)/2, rect.size.width, rect.size.height);*/
    
     _titleLabel.frame = CGRectMake((kUIScreenWidth - rect.size.width)/2,kNavStatusHeight +  (44 - rect.size.height)/2, rect.size.width, rect.size.height);
    
    if (NO) {
        [_rightButton setBackgroundImage:[UIImage imageNamed:@"nav_user" ] forState:UIControlStateNormal];
       [_rightButton setTitle:@"" forState:UIControlStateNormal
     ];
        
        _rightButton.frame =CGRectMake(kUIScreenWidth-kNavButtonWidth, kNavStatusHeight, kNavButtonWidth, kNavButtonHeight);
        
    }else{
        [_rightButton setBackgroundImage:nil forState:UIControlStateNormal];
        [_rightButton setTitle:@"登陆/注册" forState:UIControlStateNormal];
       
        _rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
        _rightButton.frame =CGRectMake(kUIScreenWidth -(kNavButtonWidth*2), kNavStatusHeight, kNavButtonWidth*2, kNavButtonHeight);
        
        
    
    }
}
@end
